//
//  BoardData.m
//  Maciago
//
//  Created by mmarcos on Wed Oct 03 2001.
//  Copyright (c) 2001 __CompanyName__. All rights reserved.
//

#import "board_data.h"


struct board_data *board_data_create (int boardSize)
{
    struct board_data *data = malloc(sizeof(struct board_data));
    data->size = boardSize;
    data->wStables = 0;
    data->bStables = 0;
    data->next = NULL;
    return data;
}

void board_data_dispose (struct board_data *data)
{
    free (data);
}

int numberOfBlacks (struct board_data *data)
{
    int i, j, nBlacks = 0;
    for (i = 0; i < data->size; ++i)
    {
        for (j = 0; j < data->size; ++j)
        {
            if ((data->cell[i][j] & kBlackPiece)  && !(data->cell[i][j] & kLegalMove))
                ++nBlacks;
        }
    }
    return nBlacks;
}

int numberOfWhites (struct board_data *data)
{
    int i, j, nWhites = 0;
    for (i = 0; i < data->size; ++i)
    {
        for (j = 0; j < data->size; ++j)
        {
            if ((data->cell[i][j] & kWhitePiece)  && !(data->cell[i][j] & kLegalMove))
                ++nWhites;
        }
    }
    return nWhites;
}

struct board_data *board_data_copy (struct board_data *data)
{
    struct board_data *temp = malloc (sizeof(struct board_data));
    return memcpy (temp, data, sizeof(struct board_data));
}